const mysql = require('mysql2/promise');

async function checkItemsTable() {
    const connection = await mysql.createConnection({
        host: '43.143.253.188',
        user: 'nextjs',
        password: 'yEAiRE2jcxTyRBy5',
        database: 'nextjs'
    });

    try {
        console.log('🔍 检查items表状态...\n');

        // 检查items表是否存在
        const [tables] = await connection.execute("SHOW TABLES LIKE 'items'");
        if (tables.length === 0) {
            console.log('❌ items表不存在');
            return;
        }

        console.log('✅ items表存在');

        // 检查表结构
        const [columns] = await connection.execute("DESCRIBE items");
        console.log('📋 表结构:');
        columns.forEach(col => {
            console.log(`   ${col.Field} - ${col.Type} - ${col.Null} - ${col.Key} - ${col.Default} - ${col.Extra}`);
        });

        // 检查数据
        const [rows] = await connection.execute("SELECT COUNT(*) as count FROM items");
        console.log(`\n📊 数据行数: ${rows[0].count}`);

        if (rows[0].count > 0) {
            // 检查价格字段
            console.log('\n💰 检查价格字段...');

            // 查看金币价格字段
            const [goldPriceData] = await connection.execute(`
                SELECT id, name, goldPrice, silverPrice, level, status, isOnSale 
                FROM items 
                WHERE goldPrice > 0 
                ORDER BY goldPrice ASC 
                LIMIT 10
            `);

            if (goldPriceData.length > 0) {
                console.log('🪙 金币价格商品 (前10个):');
                goldPriceData.forEach(item => {
                    console.log(`   ID: ${item.id}, 名称: ${item.name}, 金币价格: ${item.goldPrice}, 等级: ${item.level}`);
                });
            } else {
                console.log('⚠️  没有找到金币价格的商品');
            }

            // 查看银币价格字段
            const [silverPriceData] = await connection.execute(`
                SELECT id, name, goldPrice, silverPrice, level, status, isOnSale 
                FROM items 
                WHERE silverPrice > 0 
                ORDER BY silverPrice ASC 
                LIMIT 10
            `);

            if (silverPriceData.length > 0) {
                console.log('\n🏥 银币价格商品 (前10个):');
                silverPriceData.forEach(item => {
                    console.log(`   ID: ${item.id}, 名称: ${item.name}, 银币价格: ${item.silverPrice}, 等级: ${item.level}`);
                });
            } else {
                console.log('⚠️  没有找到银币价格的商品');
            }

            // 检查标准指令文档中提到的商品
            console.log('\n📋 检查标准指令文档中的商品...');
            const standardItems = [68, 69, 78, 79, 80, 81, 82, 85, 157, 158, 159, 414, 651, 653, 655, 656];

            for (const itemId of standardItems) {
                const [item] = await connection.execute("SELECT id, name, goldPrice, silverPrice, level, status, isOnSale FROM items WHERE id = ?", [itemId]);
                if (item.length > 0) {
                    const data = item[0];
                    console.log(`   ID: ${data.id}, 名称: ${data.name}`);
                    console.log(`      金币价格: ${data.goldPrice}, 银币价格: ${data.silverPrice}, 等级: ${data.level}`);
                    console.log(`      状态: ${data.status}, 上架: ${data.isOnSale}`);
                } else {
                    console.log(`   ID: ${itemId}: 商品不存在`);
                }
            }

        }

    } catch (error) {
        console.error('❌ 检查失败:', error.message);
    } finally {
        await connection.end();
    }
}

checkItemsTable().catch(console.error); 